//package com.doubletick.proxy.liao;
//import org.apache.hc.client5.http.auth.AuthScope;
//import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
//import org.apache.hc.client5.http.classic.methods.HttpGet;
//import org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider;
//import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
//import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
//import org.apache.hc.client5.http.impl.classic.HttpClients;
//import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;
//import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
//import org.apache.hc.core5.http.HttpHost;
//import org.apache.hc.core5.http.ParseException;
//import org.apache.hc.core5.http.io.entity.EntityUtils;
//import org.apache.hc.core5.util.Timeout;
//
//import java.io.IOException;
//import java.nio.charset.StandardCharsets;
//import java.util.Base64;
//
//public class Http5Test {
//
//    public static void main(String[] args) throws Exception {
//        //String proxyHost = "127.0.0.1";
////        String proxyHost = "192.168.220.1";
////        int proxyPort = 7890;
////        String proxyUser = "Clash";
////        String proxyPass = "123456";
//        String proxyHost = "bra.ppfly.xyz";
//        int proxyPort = 1081;
//        String proxyUser = "feng005-res-US-session-212236";
//        String proxyPass = "feng005";
//
//        // 设置代理认证
//        BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
//        credsProvider.setCredentials(
//                new AuthScope(proxyHost, proxyPort),
//                new UsernamePasswordCredentials(proxyUser, proxyPass.toCharArray()));
//
//        // 创建连接管理器
//        PoolingHttpClientConnectionManager connManager = PoolingHttpClientConnectionManagerBuilder.create()
//                .setMaxConnPerRoute(3000)
//                .setMaxConnTotal(3000)
//                .build();
//
//        // 创建HttpClient
//        HttpHost proxy = new HttpHost(proxyHost, proxyPort);
//        CloseableHttpClient httpClient = HttpClients.custom()
//                .setConnectionManager(connManager)
//                .setDefaultCredentialsProvider(credsProvider)
//                .setProxy(proxy) // 设置代理
//                .evictExpiredConnections()
//                .evictIdleConnections(Timeout.ofMinutes(1))
//                .build();
//
//        // 创建Http请求
//        HttpGet request = new HttpGet("http://ipinfo.io/");
//        request.setHeader("Connection", "close");
//
//        // 手动添加 Proxy-Authorization 头
//        String auth = proxyUser + ":" + proxyPass;
//        byte[] encodedAuth = Base64.getEncoder().encode(auth.getBytes(StandardCharsets.ISO_8859_1));
//        String authHeader = "Basic " + new String(encodedAuth);
//        request.setHeader("Proxy-Authorization", authHeader);
//
//        // 设置超时
//        //request.setConnectTimeout(Timeout.ofSeconds(10));
//        //request.setResponseTimeout(Timeout.ofSeconds(10));
//
//        // 执行请求并处理响应
//        try (CloseableHttpResponse response = httpClient.execute(request)) {
//            if (response.getCode() >= 300) {
//                EntityUtils.consume(response.getEntity());
//                System.out.println("Response code: " + response.getCode());
//                return;
//            }
//
//            if (response.getEntity() == null) {
//                System.out.println("No response entity");
//                return;
//            }
//
//            byte[] bytes = EntityUtils.toByteArray(response.getEntity());
//            if (bytes == null || bytes.length == 0) {
//                System.out.println("Empty response entity");
//                return;
//            }
//
//            String body = new String(bytes, StandardCharsets.UTF_8);
//            System.out.println("Response body: " + body);
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//    }
//
//}
